package org.ruoyi.knowledge.chain.vectorizer;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * 文本向量化
 * @author huangkh
 */
@Component
@Slf4j
public class VectorizationFactory {

    private final OpenAiVectorization openAiVectorization;
    private final RagflowVectorization ragflowVectorization;

    @Value("${chat.api.host:}")
    private String apiHost;

    public VectorizationFactory(OpenAiVectorization openAiVectorization, 
                               RagflowVectorization ragflowVectorization) {
        this.openAiVectorization = openAiVectorization;
        this.ragflowVectorization = ragflowVectorization;
    }

    public Vectorization getEmbedding(){
        // 暂时禁用Ragflow向量化，使用OpenAI向量化
        // TODO: 修复Ragflow向量化API问题后重新启用
        log.info("使用OpenAI向量化服务: {}", apiHost);
        return openAiVectorization;
        
        // 根据API地址判断使用哪种向量化实现
        // if (apiHost != null && apiHost.contains("192.168.0.150")) {
        //     log.info("使用Ragflow向量化服务: {}", apiHost);
        //     return ragflowVectorization;
        // } else {
        //     log.info("使用OpenAI向量化服务: {}", apiHost);
        //     return openAiVectorization;
        // }
    }
}
